<?php
/**
 *
 * 功能描述（留言数据）
 *
 * @author suoya <jlusuoya@gmail.com>
 * @version 1
 */

class ModelLvmsg extends ModelBase
{
	function GetList($type, $status, $page, $key, $keyword)
	{
		$where = "1";
		if($type != 0)
			$where .= " and type= $type";
		if($status != 0)
			$where .= " and status = $status";
		if(!empty($key) && !empty($keyword))
			$where .= " and $key like '%$keyword%'";
		$data  = $this->db->getRow("message", 'count(1) cnt', $where);
		if($data['cnt'] == 0)
			return array('cnt' => 0, 'pageCnt' => 0, 'data' => array());

		$retData = array('cnt' => $data['cnt'], 'pageCnt' => ceil($data['cnt'] / MSG_PAGESIZE));
		$limit = MSG_PAGESIZE * ($page - 1) . ", " . MSG_PAGESIZE;
		$data = $this->db->getAll("message", "id, userid, username, status, createtime, title, content, type, file, attach", $where, 'createtime desc', $limit);
		$retData['data'] = $data;
		return $retData;
	}

	function UpdateMsg($data, $id)
	{
		$cnt = $this->db->Update("message", $data, "id = $id");
		return $cnt;
	}

	function RemoveMsg($id)
	{
		$cnt = $this->db->Delete("message", "id = $id");
		return $cnt;
	}

	function GetAttach($id)
	{
		$data = $this->db->getRow("message", "attach", "id = $id");
		if(!$data)
			return false;
		return $data['attach'];
	}
}

